﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

using ApplProtocol;


public class NetworkInterface : MonoBehaviour
{
    public int beatInterval = 60; //frames

    private int frameCounter = 0;


    void FixedUpdate()
    {
        if (SocketObject.Connected)
        {
            frameCounter = (frameCounter + 1) % beatInterval;

            if (frameCounter % beatInterval == 0)
            {
                string pclStr = PclUtils.Load(ApplProtocolType.heartBeat);
                SocketObject.SendString(pclStr);
                Debug.Log("hb");
            }
        }
    }

    void Update()
    {
        if(SocketObject.MsgList.Count > 0)
        {
            string handleString = SocketObject.MsgList[0];
            //Debug.Log(handleString);
            if(PclUtils.Unload(handleString))
                SocketObject.MsgList.Remove(handleString);
        }
    }

    public void OnApplicationQuit()
    {
        SocketObject.Disconnect();
    }
}
